package com.donger.business.modules.dynamicForm.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.donger.auth.utils.SecurityUtil;
import com.donger.business.modules.dynamicForm.entity.SysFormDesign;
import com.donger.business.modules.dynamicForm.mapper.SysFormDesignMapper;
import com.donger.business.modules.dynamicForm.service.SysFormDesignService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class SysFormDesignServiceImpl extends ServiceImpl<SysFormDesignMapper, SysFormDesign> implements SysFormDesignService {
    /**
     * @param id
     * @param jsonData
     * @return
     */
    @Override
    public Boolean saveJson(Long id, String jsonData) {
        SysFormDesign sysFormDesign = baseMapper.selectById(id);
        sysFormDesign.setVersion(sysFormDesign.getVersion() + 1);
        sysFormDesign.setJsonData(jsonData);
        sysFormDesign.setUpdateTime(LocalDateTime.now());
        baseMapper.updateById(sysFormDesign);
        return Boolean.TRUE;
    }

    @Override
    public Boolean saveForm(SysFormDesign formDesign) {
        formDesign.setUpdateTime(LocalDateTime.now());
        formDesign.setUpdateName(SecurityUtil.getUser().getUsername());
        this.saveOrUpdate(formDesign);
        return Boolean.TRUE;
    }
}
